package com.tz.cartelo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.tz.cartelo.R;
import com.tz.cartelo.model.GoodsType;
import com.tz.cartelo.view.MyGridView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by ok on 2016/9/18.
 */
public class GoodsClassifyAdapter extends BaseAdapter {
    private LayoutInflater mLayoutInflater;
    private Context mContext;
    private List<GoodsType> mGoodsTypeList;
    private OnClassifyDetailsClickListener mOnClassifyDetailsClickListener;


    public GoodsClassifyAdapter(Context context, List<GoodsType> goodsTypeList) {
        mLayoutInflater = LayoutInflater.from(context);
        mContext = context;
        mGoodsTypeList = goodsTypeList;
    }

    @Override
    public int getCount() {
        return mGoodsTypeList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
//        if (view == null) {
        view = mLayoutInflater.inflate(R.layout.item_goods_classify, null);
        holder = new ViewHolder();
        holder.goodsClassifyTitle = (TextView) view.findViewById(R.id.goods_classify_title);
        holder.goodsClassifyGrid = (MyGridView) view.findViewById(R.id.goods_classify_grid);
        view.setTag(holder);
//        } else {
//            holder = (ViewHolder) view.getTag();
//        }

//        ImageLoader.getInstance().displayImage("drawable://" + R.mipmap.ic_jade_pic, holder.itemJadeImg, CommonUtils.options());
//        ImageLoader.getInstance().displayImage(mTopicList.get(i).getAvatar(), holder.itemJadeImg, CommonUtils.options());

        holder.goodsClassifyTitle.setText(mGoodsTypeList.get(i).getTitle());
        GoodsClassifyGridAdapter goodsClassifyGridAdapter = new GoodsClassifyGridAdapter(mContext,mGoodsTypeList.get(i).getGoodsCategoryList());
        holder.goodsClassifyGrid.setAdapter(goodsClassifyGridAdapter);
        holder.goodsClassifyGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (mOnClassifyDetailsClickListener != null)
                    mOnClassifyDetailsClickListener.onUserClick(i, position);
            }
        });

        return view;
    }

    private class ViewHolder {
        TextView goodsClassifyTitle;
        MyGridView goodsClassifyGrid;
    }

    public interface OnClassifyDetailsClickListener {
        void onUserClick(int position, int positionDetails);
    }

    public void setOnClassifyDetailsClickListener(OnClassifyDetailsClickListener onClassifyDetailsClickListener) {
        this.mOnClassifyDetailsClickListener = onClassifyDetailsClickListener;
    }


}
